package  
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.utils.*;
	import iso.*;
	
	/**
	 * 图形 Ios 图形测试
	 * @author StefanieKaka
	 */
	public final class GraphicsTest extends Sprite 
	{
		/// 构造函数
		public function GraphicsTest() 
		{
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			
			m_world = new IsoWorld();
			m_world.x = this.stage.stageWidth / 2;
			m_world.y = 0;
			this.addChild(m_world);
			
			for (var i : int = 0; i < 20; ++i)
			{
				for (var j : int = 0; j < 20; ++j)
				{
					var tile : GraphicTile = new GraphicTile(32, Tile01, 32, 16);
					tile.position = new Point3D(i * 32, 0, j * 32);
					m_world.addChildToFloor(tile);
				}
			}
			
			this.stage.addEventListener(MouseEvent.MOUSE_DOWN, onWorldClick);
		}
		
		/// 鼠标点击事件
		private function onWorldClick(event : MouseEvent) : void
		{
			var box : GraphicTile = new GraphicTile(32, Tile02, 32, 48);
			var pos : Point3D = IsoUtils.screenToIso(new Point(m_world.mouseX, m_world.mouseY));
			pos.x = Math.round(pos.x / 20) * 20;
			pos.y = Math.round(pos.y / 20) * 20;
			pos.z = Math.round(pos.z / 20) * 20;
			box.position = pos;
			m_world.addChildToWorld(box);
			m_world.sort();
		}
		
		private var m_world : IsoWorld = null;
		
		[Embed(source="../lib/tile.png")]
		private var Tile01 : Class;
		
		[Embed(source="../lib/unit.png")]
		private var Tile02 : Class;
	}

}